package io.renren.modules.usian.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.usian.entity.TeacherEntity;
import io.renren.modules.usian.service.TeacherService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * @author ???
 * @email 2072304792@qq.com
 * @date 2022-10-26 17:02:30
 */
@RestController
@RequestMapping("usian/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    // @RequiresPermissions("usian:teacher:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = teacherService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    // @RequiresPermissions("usian:teacher:info")
    public R info(@PathVariable("id") Integer id) {
        TeacherEntity teacher = teacherService.getById(id);

        return R.ok().put("teacher", teacher);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    // @RequiresPermissions("usian:teacher:save")
    public R save(@RequestBody TeacherEntity teacher) {
        teacherService.save(teacher);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    // @RequiresPermissions("usian:teacher:update")
    public R update(@RequestBody TeacherEntity teacher) {
        teacherService.updateById(teacher);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    // @RequiresPermissions("usian:teacher:delete")
    public R delete(@RequestBody Integer[] ids) {
        teacherService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @RequestMapping("/showListBycidAndRole")
    // @RequiresPermissions("usian:teacher:delete")
    public R showListBycid(int cid, int role) {
        List<TeacherEntity> list = teacherService.showListBycid(cid, role);
        return R.ok().put("list", list);
    }
}
